package com.mdd.front.controller.yangyangLeadingEnterprise.index;

import com.mdd.common.aop.NotLogin;
import com.mdd.common.entity.yangyangLeadingEnterprise.TAppClubActivity;
import com.mdd.common.entity.yangyangLeadingEnterprise.common.JsonReturn;
import com.mdd.common.entity.yangyangLeadingEnterprise.param.AppUserActivityRegistrationParam;
import com.mdd.common.entity.yangyangLeadingEnterprise.param.ClubActivityParam;
import com.mdd.common.entity.yangyangLeadingEnterprise.param.CommonParam;
import com.mdd.front.service.yangyangLeadingEnterprise.ITAppClubActivityService;
import com.mdd.front.service.yangyangLeadingEnterprise.ITAppUserActivityRegistrationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("api.index/activity")
@Api(tags = "app首页---领企俱乐部活动管理")
public class TAppClubActivityController {

    @Resource
    ITAppClubActivityService appClubActivityService;

    @Resource
    ITAppUserActivityRegistrationService appUserActivityRegistrationService;

//    @GetMapping("/list")
//    @ApiOperation(value="俱乐部活动列表")
//    public AjaxResult<PageResult<TAppClubActivityListedVo>> list(@Validated PageValidate pageValidate,
//                                                     @Validated TAppClubActivitySearchValidate searchValidate) {
//        PageResult<TAppClubActivityListedVo> list = iTAppClubActivityService.list(pageValidate, searchValidate);
//        return AjaxResult.success(list);
//    }

    @NotLogin
    @PostMapping(value = "/selectList",produces = "application/json; charset=UTF-8")
    @ApiOperation(value="俱乐部活动列表")
    public String selectList(@RequestBody ClubActivityParam param, HttpServletRequest request) {
        List<TAppClubActivity> appClubActivityList= appClubActivityService.selectList(param);
        return JsonReturn.success().setListData(appClubActivityList).toJsonStr();
    }

    @NotLogin
    @PostMapping(value = "/selectActivityById",produces = "application/json; charset=UTF-8")
    @ApiOperation(value="俱乐部活动详情")
    public String selectActivityById(@RequestBody CommonParam param) {
        Integer activityId = param.getId();
        if (activityId == null) {
            return JsonReturn.fail("必传信息不能为空",40001).toJsonStr();
        }
        return appClubActivityService.selectActivityById(activityId);
    }

    /**
     * 设置报名提醒/立即报名/取消报名
     * @param param
     * @return
     */
    @NotLogin
    @PostMapping(value = "/updateUserActivityRegistration",produces = "application/json; charset=UTF-8")
    @ApiOperation(value="设置报名提醒/立即报名/取消报名")
    public String updateUserActivityRegistration(@RequestBody AppUserActivityRegistrationParam param) {
        Integer activityId = param.getActivityId();
        Integer userId = param.getUserId();
        Integer type = param.getType();
        if (activityId == null || userId == null || type == null) {
            return JsonReturn.fail("必传信息不能为空",40001).toJsonStr();
        }
        return appUserActivityRegistrationService.updateUserActivityRegistration(param);
    }


}
